package com.niubility.server.Impl;


import com.niubility.dao.DepartmentDao;
import com.niubility.entity.Department;
import com.niubility.server.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DepartmentService implements IDepartmentService {
    @Autowired
    private DepartmentDao departmentDao;


    //通过ID获取社团数据
    public Department loadDepById(int depId){
        return departmentDao.loadDepById(depId);
    }


    //通过账号获取社团
    public Department loadDepByAcount(String depAcount) {
         return departmentDao.loadDepByAcount(depAcount);
    }


    //增加新社团
    public boolean addDep(Department department) {
        //System.out.println("社团表添加");
        return departmentDao.save(department)>0?true:false;
    }


    //社团信息更新
    public boolean update(Department department) {
        int i=departmentDao.update(department);
        return i>0?true:false;
    }


    //新人加入社团，社团总人数增加
    public boolean changeDepNum(int depId,int changeValue){
        int i=departmentDao.depNumAdd(depId,changeValue);
        return i>0?true:false;
    }

    //删除社团
    public boolean delDepById(int depId){
        int i=departmentDao.delDepById(depId);
        return i>0?true:false;
    }


    //提供学校ID，查找属于该学校的所有社团
    public List<Department> loadAllInCol(int colId,int page,int elemCount) {
        int index=(page-1)*elemCount;
        List<Department> departmentList=departmentDao.loadAllInCol(colId,index,elemCount+1);
        return departmentList;
    }

    //查出最后一次插入的ID
    public int lastInsertId(int colId,String depName){
        return departmentDao.lastInsertId(colId,depName);
    }
}